-
-
Notifications
You must be signed in to change notification settings - Fork 7
fix(mqtt): fixed how mqtt library is imported #514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Because of some issues with some bundlers (namely, Parcel 2) we have updated the way mqtt.connect is imported in Connection.ts Minor updates to index.ts (eslint) Added a changelog section in readme file
Minor fixes
|
Regenerated package-lock.json
Updated TokenConnectionBuilder constructor to use the right mqtt.connect function
src/connection/Connection.ts
Outdated
@@ -106,7 +111,8 @@ export class Connection implements IConnection { | |||
else valueToSend = value; | |||
}); | |||
|
|||
if (valueToSend !== {}) messages.push({ topic, propertyName: current, value: valueToSend }); | |||
// the condition `if (valueToSend !== {}) ` has been removed bc it always evaluates to true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: maybe here is worth understanding if is better to remove the if
or leaving the if
fixing the condition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, it makes sense, I'm going to see if I can understand the original intention
Added a check before sending MQTT empty objects.
src/connection/Connection.ts
Outdated
if (valueToSend !== {}) messages.push({ topic, propertyName: current, value: valueToSend }); | ||
// If the message is an object, and it's empty, it makes no sense to send it | ||
// All other messages (e.g. non-empty objects or primitives) must be sent | ||
if (!(typeof valueToSend === 'object' && Object.keys(valueToSend).length == 0)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fabioimpe do you think it's ok now, with an explicit check on the object and its length?
I think now is more explicit that:
- if it's an empty object, skip sending the message
- if it's a non-empty object, or any other value (primitive) then send it.
I thing it's rather an edge-case, which probably happens if the properties
array is empty (so forEach
statement is never executed) or value
at line 111 is an empty object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think now is cleaner.
Maybe you can think about extracting the condition to be more readable, but this seems the right way 👍
Because of some issues with some bundlers (namely, Parcel 2) we have updated the way mqtt.connect is imported in Connection.ts
Minor updates to index.ts (eslint)
Added a changelog section in readme file